
<{extends file="$elementPath/layout/index.html"}>
<{block name='body'}>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                        <{if model_admin_users::check_right("$module/$controller/save")}>
                        <button class="layui-btn add-new-row">创建管理员</button>
                        <{/if}>
                    </div>
                    <table class="layui-hide" id="role-table-page" lay-filter="role-table-action"></table>
                    <script type="text/html" id="role-table-action">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>

                    <script type="text/html" id="userlist-status-btn">
                        {{#  if(d.status == 1){ }}
                        <button class="layui-btn layui-btn-xs">正常</button>
                        {{#  } else { }}
                        <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button>
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use(['index', 'table'], function () {
        var table = layui.table;
        table.render({
            elem: '#role-table-page'
            , url: '/<{$module}>/<{$controller}>/index?do=list'
            , limit:30
            , height: 'full-100'//一行条件
            , cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true}
                , {field: 'username', title: '用户名'}
                , {field: 'group_name', title: '角色组'}
                , {field: 'truename', title: '真实姓名'}
                , {field: 'email', title: 'E-mail'}
                , {field: "status",title: "状态",templet: "#userlist-status-btn",minWidth: 80,align: "center"}
                , {width: 180, align: 'center', fixed: 'right', toolbar: '#role-table-action'}
            ]]
            , page: true
        });

        var $ = layui.$, active = {
            edit: function (obj) { //获取选中数据
                var data = obj.data;
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '/<{$module}>/<{$controller}>/save/id/' + data.id
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#role-form-submit");
                        submit.click();
                    }
                });
            }
            , del: function (obj) {
                var data = obj.data;
                layer.confirm('确定需要删除吗?', function (index) {
                    $.post('/<{$module}>/<{$controller}>/del/id/'+data.id+'?isajax=1&',{},function (res) {
                        layer.msg(res.msg);
                    },'json');
                    table.reload('role-table-page');
                    layer.close(index);
                });
            }
            , add: function () {
                layer.open({
                    type: 2
                    , title: '添加'
                    , content: '/<{$module}>/<{$controller}>/save'
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#role-form-submit");
                        submit.click();
                    }
                });
            }
        };
        //监听工具条
        table.on('tool(role-table-action)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        $('.add-new-row').on('click', function () {
            var type = $(this).data('type');
            active['add'].call(this)
        });
    });
</script>
<{/block}>